Imports System
Imports System.Collections
Imports System.IO

Public Class TextStopWordProvider

    Private _path As String
    Private _stopWords As String()
    Public Shared ARQUIVO_PALAVRAS_PADRAO As String = "StopWords_POR_BRA.txt"

    Public Sub New()
        Me.New(TextStopWordProvider.ARQUIVO_PALAVRAS_PADRAO)
    End Sub

    Public Sub New(ByVal nomeArquivo As String)
        Me._path = (Directory.GetCurrentDirectory & "\" & nomeArquivo)
        Me.Inicializa()
    End Sub

    Protected Sub Inicializa()
        Dim listaPalavras As New ArrayList
        Dim reader As TextReader = File.OpenText(Me._path)

        Dim palavras As String() = reader.ReadToEnd.Split(vbNewLine)
        reader.Close()
        listaPalavras.AddRange(palavras)
        Me._stopWords = DirectCast(listaPalavras.ToArray(GetType(String)), String())
        Array.Sort(Of String)(Me._stopWords)
    End Sub

    Public Function IsStopWord(ByVal word As String) As Boolean
        Return (Array.BinarySearch(Of String)(Me._stopWords, word) >= 0)
    End Function

End Class

